from PyQt6.QtWidgets import QApplication, QLabel, QWidget
from PyQt6.QtGui import QPixmap, QTransform
from PyQt6.QtCore import QTimer

class RotatingLabel(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("旋转标签")
        self.setGeometry(300, 300, 400, 400)

        # 初始化 QLabel
        self.label = QLabel(self)
        # self.pixmap =  # 替换为你的图片路径
        self.label.setPixmap(QPixmap("src/CAR.png"))
        self.label.setGeometry(100, 100, 200, 200)

        # 初始化定时器
        self.angle = 0
        self.timer = QTimer(self)
        self.timer.timeout.connect(self.rotate_image)
        self.timer.start(50) # 每50毫秒更新一次

    def rotate_image(self):
        transform = QTransform().rotate(self.angle)
        rotated_pixmap = QPixmap("src/CAR.png").transformed(transform)
        self.label.setPixmap(rotated_pixmap)
        self.angle = (self.angle + 5) % 360

if __name__ == "__main__":
    import sys
    app = QApplication(sys.argv)
    window = RotatingLabel()
    window.show()
    sys.exit(app.exec())